unit UVRRecordedTaskFrame;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, sppngimagelist, StdCtrls, ShellAPI,
  SkinCtrls, ExtCtrls, SkinData, DynamicSkinForm,
  UVRConsts, UVRUtils, UVRClasses;

type
  TRecordedTaskFrame = class(TFrame)
    spSkinFrame: TspSkinFrame;
    pnlSeperator: TspSkinPanel;
    pnlBackground: TPanel;
    imgType: TspPngImageView;
    lblCaption: TspSkinStdLabel;
    lbl1: TspSkinStdLabel;
    lblOutputFormat: TspSkinStdLabel;
    lblStartTime: TspSkinStdLabel;
    lblDurationTime: TspSkinStdLabel;
    lbl2: TspSkinStdLabel;
    imgPreview: TImage;
    lblEndTime: TspSkinStdLabel;
    pnlForward: TspSkinPanel;
    procedure pnlForwardClick(Sender: TObject);
    procedure pnlBackgroundEnter(Sender: TObject);
    procedure pnlBackgroundExit(Sender: TObject);
    procedure pnlSeperatorClick(Sender: TObject);
    procedure pnlForwardDblClick(Sender: TObject);
  private
    { Private declarations }
    FFileName: string;
    
    procedure SetSkinData(aSkinData: TspSkinData);

    procedure SetTypeImageList(aPngImageList: TspPngImageList);
    procedure SetTypeImageIndex(aIndex: Integer);
    function GetTypeImageIndex: Integer;

    procedure SetCaption(aCaption: TCaption);
    function GetCaption: TCaption;

    procedure SetDurationTime(aDateTime: TDateTime);
    function GetDurationTime: TDateTime;

    procedure SetStartTime(aDateTime: TDateTime);
    function GetStartTime: TDateTime;

    procedure SetEndTime(aDateTime: TDateTime);
    function GetEndTime: TDateTime;
  public
    { Public declarations }
  published
    property TypeImageList: TspPngImageList write SetTypeImageList;
    property TypeImageIndex: Integer read GetTypeImageIndex write SetTypeImageIndex;
    property Caption: TCaption read GetCaption write SetCaption;
    property FileName: string read FFileName write FFileName;
    property StartTime: TDateTime write SetStartTime;
    property EndTime:   TDateTime write SetEndTime;
    property SkinData: TspSkinData write SetSkinData;
  end;

implementation

{$R *.dfm}

{ TRecordedTaskFrame }

function TRecordedTaskFrame.GetCaption: TCaption;
begin
  Result := lblCaption.Caption;
end;

function TRecordedTaskFrame.GetDurationTime: TDateTime;
begin
  Result := StrToDateTimeDef(lblDurationTime.Caption, 0);
end;

function TRecordedTaskFrame.GetTypeImageIndex: Integer;
begin
  Result := imgType.ImageIndex;
end;

procedure TRecordedTaskFrame.SetCaption(aCaption: TCaption);
begin
  lblCaption.Caption := ShortenStr(aCaption);
end;

procedure TRecordedTaskFrame.SetDurationTime(aDateTime: TDateTime);
begin
  lblDurationTime.Caption := FormatDateTime(UVRConsts.SVRDateTimeFormat, aDateTime);
end;

procedure TRecordedTaskFrame.SetSkinData(aSkinData: TspSkinData);
begin
  spSkinFrame.SkinData := aSkinData;
  lbl1.SkinData := aSkinData;
  lbl2.SkinData := aSkinData;
  lblCaption.SkinData := aSkinData;
  lblStartTime.SkinData := aSkinData;
  lblEndTime.SkinData := aSkinData;
  lblOutputFormat.SkinData := aSkinData;
  lblDurationTime.SkinData := aSkinData;
  pnlSeperator.SkinData := aSkinData;
end;

procedure TRecordedTaskFrame.SetTypeImageIndex(aIndex: Integer);
begin
  imgType.ImageIndex := aIndex;
end;

procedure TRecordedTaskFrame.SetTypeImageList(
  aPngImageList: TspPngImageList);
begin
  imgType.PngImageList := aPngImageList;
end;

function TRecordedTaskFrame.GetEndTime: TDateTime;
begin
  Result := StrToDateTimeDef(lblEndTime.Caption, 0);
end;

function TRecordedTaskFrame.GetStartTime: TDateTime;
begin
  Result := StrToDateTimeDef(lblStartTime.Caption, 0);
end;

procedure TRecordedTaskFrame.SetEndTime(aDateTime: TDateTime);
begin
  if aDateTime <> CVR_NULL_VALUE then
    lblEndTime.Caption := FormatDateTime(UVRConsts.SVRDateTimeFormat, aDateTime);
end;

procedure TRecordedTaskFrame.SetStartTime(aDateTime: TDateTime);
begin
  if aDateTime <> CVR_NULL_VALUE then
    lblStartTime.Caption := FormatDateTime(UVRConsts.SVRDateTimeFormat, aDateTime);
end;

procedure TRecordedTaskFrame.pnlForwardClick(Sender: TObject);
begin
  pnlBackground.SetFocus;
end;

procedure TRecordedTaskFrame.pnlBackgroundEnter(Sender: TObject);
begin
  pnlBackground.Color := clHighlight;
end;

procedure TRecordedTaskFrame.pnlBackgroundExit(Sender: TObject);
begin
  pnlBackground.Color := clBtnFace;
end;

procedure TRecordedTaskFrame.pnlSeperatorClick(Sender: TObject);
begin
  Self.OnExit(Self);
  Self.pnlBackground.OnExit(Self);
end;

procedure TRecordedTaskFrame.pnlForwardDblClick(Sender: TObject);
begin
  ShellExecute(Self.Handle, nil, PChar(Self.FileName), nil, nil, 1);
end;

end.
